﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdminUserManager.aspx.cs" Inherits="RegisterWeb.Manager.SystemUserManager.AdminUserManager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>系统用户管理</title>

       <link href="../../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-easyui-1.2.6/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>

<script type="text/javascript">

    var url; //提交数据的路径
    var formId;//当天要提交的Form的编号
    var dialogId; //对话框的编号
    var row1;
    var successCallback = function (result) {
   //     alert(result);
        //result为请求处理后的返回值
        var result = eval('(' + result + ')');
        if (result.success) {
            $.messager.show({
                title: 'Success',
                msg: result.msg
            });
            $(dialogId).dialog('close');
            $('#dg').datagrid('reload');
        } else {
            $.messager.show({
                title: 'Error',
                msg: result.msg
            });
        }
    }

    function DeleteUserRole() {
       var row = $('#tt').datagrid('getSelected');
        if (confirm("确定要删除该角色吗？")) {
            $.post("../Manager/ashx/HandlerShowTime_Price.ashx", { "action": "delete", "Id": id }, function (data, status) {
                if (status == "success") {
                    if (data == "ok") {
                        alert("该价格删除成功！");
                    }
                    else
                        alert("删除失败！");
                }
                else
                    alert("网络连接错误，删除失败！");
            });
        }
    }
    function addUserRole() {
        row = $('#tt').datagrid('getSelected');
        if (confirm("确定要添加该角色吗？")) {
            $.post("../Manager/ashx/HandlerShowTime_Price.ashx", { "action": "delete", "Id": id }, function (data, status) {
                if (status == "success") {
                    if (data == "ok") {
                        alert("该角色添加成功！");
                    }
                    else
                        alert("添加失败！");
                }
                else
                    alert("网络连接错误，删除失败！");
            });
        }
    }

    $(function () {
        //预加载编辑框
      
        $("#editAdminUser").dialog({
            "title": "编辑用户信息",
            width: 420,
            height: 300,
            href: 'EditAdminUser.aspx'
        });
        $("#editAdminUser").dialog('open').dialog('close');
        $('#dg').datagrid({
            onDblClickRow: function (rowIndex, rowData) {
                $('#editAdminUser').dialog('open');
                $("#textAdminName").val(rowData.Name);
                $("#textAdminPassword").val("");
                $("#selectHosptial").val(rowData.HosptialID);
                //      $('#edit').form('clear');
                url = 'ashx/AdminInfoManagerService.ashx?action=edit&id=' + rowData.ID;
                formId = "#edit";
                dialogId = "#editAdminUser";

            }
        });

    });
//编辑用户部分
    function ManagerUserRole() {
      
        $("#ManagerUserRole").dialog({
                "title": "用户角色管理",
                width: 450,
                height: 250,
                href: 'ManagerUserRole.aspx'
            });
     row1 = $('#dg').datagrid('getSelected');
     var   row = $('#dg').datagrid('getSelected');
        if (row) {
                $('#ManagerUserRole').dialog('open');
                url = 'ashx/AdminInfoManagerService.ashx?action=edit&id=' + row.ID;
                formId = "#userrole";
                dialogId = "#ManagerUserRole";
        }
        else {
            $.messager.alert("提示","您没有选中任何行！");
        }

    }

    function editAdminUser() {   
 var   row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#editAdminUser').dialog('open');
            $("#textAdminName").val(row.Name);
            $("#textAdminPassword").val("");
            //   $('#edit').form('clear');
            $("#selectHosptial").val(row.HosptialID);

            url = 'ashx/AdminInfoManagerService.ashx?action=edit&id=' + row.ID;
            formId = "#edit";
            dialogId = "#editAdminUser";

        }
        else {
            $.messager.alert("提示", "您没有选中任何行！");
        }
    }


    function editUser() {

      var   row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#editAdminUser').dialog('open');
            $("#textAdminName").val(row.Name);
            $("#textAdminPassword").val("");
            $("#selectHosptial").val(row.HosptialID);
            //   $('#edit').form('clear');

            url = 'ashx/AdminInfoManagerService.ashx?action=edit&id=' + row.ID;
            formId = "#edit";
            dialogId = "#editAdminUser";

        }
        else {
            $.messager.alert("提示", "您没有选中任何行！");
        }
    }



//添加用户部分
    function addAdminUser() {
        $("#addAdminUser").dialog({
            "title": "新建用户",
            width: 420,
            height: 390,
            href: 'AddAdminUser.aspx'
        });
    $('#addAdminUser').dialog('open');
    $('#add').form('clear');

    url = 'ashx/AdminInfoManagerService.ashx?action=add';
    formId = "#add";
    dialogId = "#addAdminUser";
}
function saveInfo() {
    $(formId).form('submit', {
    url:url,
    onSubmit: function () {
        return $(this).form('validate');
    },
    success: successCallback
    });
}

//  删除代码部分
    function deleteAdminUser() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('删除提示', '确定要删除' + row.Name + '吗', function (r) {
                if (r) {
                    $.post('ashx/AdminInfoManagerService.ashx', { id: row.ID, action: 'delete' }, function (data, status) {
                        if (data == "ok") {
                            $('#dg').datagrid('reload'); 
                        } else {
                            $.messager.show({	
                                title: 'Error',
                                msg: '删除该用户失败!'
                            });
                        }
                    });
                }
            });
        }
    } function UserRoleclose() {
        $('#ManagerUserRole').dialog('close')
        window.location.reload();
    
    }

    function check() {
        var value = $("#textAdminName").val();
        if (value!= "") {
            $.post('ashx/AdminInfoManagerService.ashx', { action: 'check', name: value }, function (data, status) {
                if (data == 'ok') {
                    $("#textAdminName").val("");
                    $("#error").text("用户名"+value + "已存在！");
                }
                else {
                    $("#error").text("");
                }
            });
        }
    }

</script>

</head>
<body>
    <form id="form1">
    <div region="center" title="系统用户管理">
<table id="dg" title="系统用户管理" class="easyui-datagrid" style="overflow:auto ; height:550px"
			url="ashx/AdminInfoManagerService.ashx?action=list"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true"   idField='ID'
            pageSize="20"
            >
		<thead>
			<tr>
				<th field="ID" width="50">编号</th>
				<th field="Name" width="50">用户名</th>
				<th field="HosptialName" width="50">所属单位</th>
				<th field="AddTime" width="50">添加时间</th>
                <th field="Recoder" width="50">记录人</th>
                <th field="LastRegTime" width="50">最后一次登录时间</th>
			</tr>
		</thead>
	</table>

    <div id="toolbar" style="padding:5px;height:auto">
					<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addAdminUser()">添加用户</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editAdminUser()">编辑用户</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteAdminUser()">删除用户</a>
                   <a href="#" class="easyui-linkbutton" iconCls="icon-remove"   plain="true"  onclick="ManagerUserRole()">指定角色</a>                                         
                                                                                                                                                                                             
    </div>


			<div id="addAdminUser" class="easyui-dialog" closed="true" buttons="#addAdminUser-buttons" style="padding:10px 20px">
        	</div>
			<div id="addAdminUser-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#addAdminUser').dialog('close')">关闭</a>
			</div>
            <div id="editAdminUser" class="easyui-dialog" closed="true" buttons="#editAdminUser-buttons" style="padding:10px 20px">
        	</div>
            <div id="editAdminUser-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#editAdminUser').dialog('close')">关闭</a>
			</div>
             <div id="ManagerUserRole" class="easyui-dialog" closed="true" buttons="#ManagerUserRole-buttons" style="">
        	</div>
                <div id="ManagerUserRole-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:$('#ManagerUserRole').dialog('close')">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="UserRoleclose()">关闭</a>
			</div>
    </div>
    </form>
</body>
</html>
